<!--suppress ALL -->
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">
				<el-form-item>
					<el-input v-model="filters.keyword" placeholder="操作人"></el-input>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="search()">查询</el-button>
				</el-form-item>
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="logs" highlight-current-row v-loading="listLoading" @selection-change="selsChange" style="width: 100%;">
			<el-table-column type="selection" width="55">
			</el-table-column>
			<el-table-column type="index" width="50">
			</el-table-column>
			<el-table-column prop="operator" label="操作人" width="120" sortable>
			</el-table-column>
			<el-table-column prop="operateDate" label="操作时间" width="160" sortable>
			</el-table-column>
			<el-table-column prop="httpMethod" label="请求方法" width="100" sortable>
			</el-table-column>
			<el-table-column prop="uri" label="请求地址" width="200" sortable>
			</el-table-column>
			<el-table-column prop="host" label="IP" width="200" sortable>
			</el-table-column>
			<el-table-column prop="result" label="结果" width="100" sortable>
			</el-table-column>
			<el-table-column prop="remark" label="简述" width="200" sortable>
			</el-table-column>
			<el-table-column label="操作" >
				<template  slot-scope="scope">
					<el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">删除</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
			<el-pagination layout="prev, pager, next"
						   @current-change="handleCurrentChange"
						   :page-size="pageSize"
						   :current-page="currentPage"
						   :total="total"
						   style="float:right;">
			</el-pagination>
		</el-col>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import { getDepartmentListPage, removeDepartment, batchRemoveDepartment, saveDepartment, addDepartment } from '../../api/api';

	export default {
		data() {
			return {
			    title:'',
                filters: {
                    keyword: ''
                },
				logs:[],
				options:[],
				total: 0,
				pageSize: 5,
				currentPage:1,
				listLoading: false,
				sels: [],//列表选中列

				//编辑界面数据
			}
		},
		methods: {
			search(){
			    this.currentPage=1;
                this.getLog();
			},
            batchRemove: function () {
                var ids = this.sels.map(item => item.id);
                this.$confirm('确认删除选中记录吗？', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    //NProgress.start();
                    this.$http.patch("/log",ids)
                        .then(result=>{
                            this.listLoading = false;
                            result = result.data;
                            //删除成功
                            if(result.success){
                                this.$message({
                                    message: '操作成功！',
                                    type: 'success'
                                });
                            }else{
                                this.$message({
                                    message: result.message,
                                    type: 'error'
                                });
                                //删除失败
                            }
                            //无论成功或者失败，返回首页
                            this.currentPage = 1;
                            this.getLog();
                        }).catch(result=>{
                        this.saveloading = false;
                        this.currentPage = 1;
                        this.getLog();
                    })
                }).catch(() => {

                });
            },
            handleCurrentChange(val) {
                this.currentPage = val;
                this.getLog();
            },
			//获取用户列表
			getLog() {
                //DepartmentQuery
                let para = {
                    currentPage: this.currentPage,
                    pageSize:this.pageSize,
                    keyword: this.filters.keyword
                };
                this.listLoading = true;//开启忙等框
                //NProgress.start();
				this.$http.post("/log",para)
					.then(result=>{
                        this.listLoading = false;//关闭忙等框
					    result = result.data;
                        this.total = result.total;
					    this.logs = result.rows;
					})
					.catch(result=>{
                        console.log(result);
                        this.$message({
                            message: '系统繁忙，稍后重试！！！',
                            type: 'error'
                        });
					})


				/*getDepartmentListPage(para).then((res) => {
					this.total = res.data.total;
					this.details = res.data.details;
					this.listLoading = false;
					//NProgress.done();
				});*/
			},
			//删除
			handleDel: function (index, row) {
				this.$confirm('确认删除该记录吗?', '提示', {
					type: 'warning'
				}).then(() => {
					this.listLoading = true;
					//NProgress.start();
					this.$http.delete("/log/"+row.id)
						.then(result=>{
                            this.listLoading = false;
                            result = result.data;
						    //删除成功
						    if(result.success){
                                this.$message({
                                    message: '操作成功！',
                                    type: 'success'
                                });
						    }else{
                                this.$message({
                                    message: result.message,
                                    type: 'error'
                                });
						        //删除失败
							}
							//无论成功或者失败，返回首页
                            this.currentPage = 1;
                            this.getLog();
                        })
						.catch(result=>{
                    });
				}).catch(() => {

				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
		},
		mounted() {
		    //页面加载完毕，调用pethome拿出数据
			this.getLog();
		}
	}

</script>

<style scoped>

</style>